package com.mr.cai.main.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mr.cai.main.R;
import com.mr.cai.main.activity.base.MrCaiBaseActivity;
import com.mr.cai.main.utils.CommonCoreUtil;

import rx.functions.Action1;

/**
 * Created by hai8108 on 16/2/25.
 */
public class MrCaiSettingActivity extends MrCaiBaseActivity {
    private final int MR_CAI_SETTING_INFO_NUM = 9;
    private View[] mrCaiUserInfoViews = new View[MR_CAI_SETTING_INFO_NUM];
    private ImageView[] mrCaiIconViews = new ImageView[MR_CAI_SETTING_INFO_NUM];
    private TextView[] mrCaiTextViews = new TextView[MR_CAI_SETTING_INFO_NUM];

    private int[] iconResId = {R.drawable.mr_cai_user_details, R.drawable.mr_cai_address_center, R.drawable
            .mr_cai_safe_center, R.drawable.mr_cai_comment_center, R.drawable.mr_cai_mobile_center,
            R.drawable.mr_cai_share_center, R.drawable.mr_cai_help_center, R.drawable.mr_cai_clear_cache,
            R.drawable.mr_cai_version_center};
    private int[] txtResId = {R.string.my_setting_user_details_txt, R.string.my_setting_address_txt, R.string
            .my_setting_safe_txt, R.string.my_setting_comment_txt,
            R.string.my_setting_mobile_txt, R.string.my_setting_share_txt, R.string.my_setting_help_txt
            , R.string.my_setting_clearcache_txt, R.string.my_setting_version_txt};

    public static void launch(Activity activity){
        Intent intent = new Intent(activity, MrCaiSettingActivity.class);
        activity.startActivity(intent);
    }
    @Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_mr_cai_layout);
        findView();
        initData();
    }
    private void findView(){
        CommonCoreUtil.setClickAction(findViewById(R.id.top_view).findViewById(R.id.pub_top_left)
                , new Action1() {
            @Override
            public void call (Object o) {
                finish();
            }
        });
        ((TextView)findViewById(R.id.top_view).findViewById(R.id.pub_top_mid)).setText(R.string.my_setting_user_txt);
        TextView loginOut = (TextView)findViewById(R.id.login_out);
        CommonCoreUtil.setClickAction(loginOut, new Action1() {
            @Override
            public void call (Object o) {
                finish();
            }
        });
        mrCaiUserInfoViews[0] = findViewById(R.id.mr_cai_detail_info);
        mrCaiUserInfoViews[1] = findViewById(R.id.mr_cai_address_manager);
        mrCaiUserInfoViews[2] = findViewById(R.id.mr_cai_safe_center);
        mrCaiUserInfoViews[3] = findViewById(R.id.mr_cai_comment_info);
        mrCaiUserInfoViews[4] = findViewById(R.id.mr_cai_mobile_service);
        mrCaiUserInfoViews[5] = findViewById(R.id.mr_cai_share_center);
        mrCaiUserInfoViews[5].setVisibility(View.GONE);
        mrCaiUserInfoViews[6] = findViewById(R.id.mr_cai_help_center);
        mrCaiUserInfoViews[7] = findViewById(R.id.mr_cai_clear_cache);
        mrCaiUserInfoViews[8] = findViewById(R.id.mr_cai_version_center);

        for (int i = 0; i < MR_CAI_SETTING_INFO_NUM; i++) {
            mrCaiUserInfoViews[i].setOnClickListener(onClick);
            mrCaiIconViews[i] = (ImageView) mrCaiUserInfoViews[i].findViewById(R.id
                    .mr_cai_setting_icon);
            mrCaiIconViews[i].setImageResource(iconResId[i]);
            mrCaiTextViews[i] = (TextView) mrCaiUserInfoViews[i].findViewById(R.id
                    .mr_cai_setting_txt);
            mrCaiTextViews[i].setText(txtResId[i]);
        }
    }

    private View.OnClickListener onClick = new View.OnClickListener() {
        @Override
        public void onClick (View view) {
            if(view == mrCaiUserInfoViews[0]){
                MrCaiUserInfoActivity.launch(MrCaiSettingActivity.this);
            } else if(view == mrCaiUserInfoViews[1]){
                MrCaiAddressManagerActivity.launch(MrCaiSettingActivity.this);
            }else if(view == mrCaiUserInfoViews[2]){
                MrCaiSafeCenterActivity.launch(MrCaiSettingActivity.this);
            }else if(view == mrCaiUserInfoViews[3]){
                MrCaiGoodCommentActivity.launch(MrCaiSettingActivity.this);
            }else if(view == mrCaiUserInfoViews[4]){
                CommonCoreUtil.showToast("To mobile number");
            }else if(view == mrCaiUserInfoViews[5]){

            }else if(view == mrCaiUserInfoViews[6]){
                MrCaiHelpCenterActivity.launch(MrCaiSettingActivity.this);
            }else if(view == mrCaiUserInfoViews[7]){

            }else if(view == mrCaiUserInfoViews[8]){
                MrCaiVersionCenterActivity.launch(MrCaiSettingActivity.this);
            }
        }
    };

    private void initData(){

    }
}
